<template>
    <div>
        <el-card>
            <el-table
                    :data="courseList"
                    style="width: 100%"
                    border
            >
                <el-table-column
                        prop="id"
                        label="科目ID"
                        width="180">
                </el-table-column>
                <el-table-column
                        prop="id_in_app"
                        label="APP_ID"
                        width="180">
                </el-table-column>
                <el-table-column
                        prop="name"
                        label="科目名称"
                        width="200">
                </el-table-column>
                <el-table-column
                        prop="active_days"
                        label="课程有效期">
                </el-table-column>
            </el-table>
        </el-card>
    </div>
</template>

<script>
    import {courselist} from "../../../request/api";

    export default {
        name: "index",
        props:{
            pageSize: {
                type: Number
            },
            currentPage: {
                type: Number
            }
        },
        data() {
            return {
                courseList: [],
                courseListCopy:[]
            }
        },
        methods: {
            getAllCourse() {
                courselist().then(res => {
                    console.log('所有科目', res)
                    this.courseList = res;
                    this.courseListCopy = this.courseList;
                    this.$emit('total',res.length);
                    this.courseList = this.courseList.slice((this.currentPage - 1)*this.pageSize,this.currentPage*this.pageSize);
                })
            }
        },
        watch: {
            pageSize() {
                this.courseList = this.courseListCopy;
                console.log('传递参数', this.currentPage, this.pageSize);
                this.courseList = this.courseList.slice((this.currentPage - 1)*this.pageSize,this.currentPage*this.pageSize);
            },
            currentPage() {
                this.courseList = this.courseListCopy;
                console.log('传递参数', this.currentPage, this.pageSize)
                this.courseList = this.courseList.slice((this.currentPage - 1)*this.pageSize,this.currentPage*this.pageSize);
                console.log(this.orgList)
            }
        },
        created() {
            this.getAllCourse();
        },
        mounted() {
            this.courseList = this.courseList.slice((this.currentPage - 1)*this.pageSize,this.currentPage*this.pageSize);
        }
    }
</script>

<style scoped>

</style>
